#include "comm.h" 

int main() {
    umask(0);
    if(mkfifo(FILE_NAME, 0666) < 0) {
        perror("mkfifo error");
        exit(1);
    }
    int fd = open(FILE_NAME, O_RDONLY);
    if(fd < 0) {
        perror("open error");
        exit(2);
    }
    int fdout = open("test_copy.txt", O_CREAT | O_WRONLY, 0666);
    if(fdout < 0) {
        perror("open error");
        exit(3);
    }
    char message[256];
    while(true) {
        message[0] = '\0';
        ssize_t s = read(fd, message, sizeof(message) -1);
        if(s > 0) {
            write(fdout, message, s);
        }else if(s == 0) {
            printf("client quit!\n");
            break;
        }else {
            printf("read error!\n");
            break;
        }
    }
    close(fd);
    close(fdout);
    return 0;
}


